<%--
  Created by IntelliJ IDEA.
  User: 84812
  Date: 2022/9/5
  Time: 17:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"  isELIgnored="false" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="/js/jquery-1.11.0.js"></script>

    <!-- <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>-->
    <script>

        $(function () {
            $("#btn").click(
                function () {
                    // alert("111")
                    //给输入框赋值
                    // $("#username").val("val函数赋值")
                    $.ajax({
                        type:"POST",
                        url:"/ajax/demo",
                        data:"username=hzy&age=18",
                        dataType:"text",
                        success:function (data) {
                            $("#username").val(data.username);

                        }
                    })
                }
            );
            $("#btn1").click(function () {
                $.ajax({
                    type:"POST",  //代表请求方式,默认是get请求
                    url:"/ajax/json",
                    // data:"username=steel&age=18",
                    data:'{"username":"hd","age":18}',
                    dataType:"json",
                    contentType:"application/json;charset=UTF-8",
                    success:function (data) {   //回调函数，请求成功之后执行  data返回的数据
                        //  console.log(data)
                        //$("#username").val(data)
                        console.log(data);
                        $("#username1").val(data.username);
                        $("#age").val(data.age);

                    }
                })
            })
        });
    </script>

</head>
<body>

<h1 class="hh" id="h">这是query</h1>
<button id="btn">按钮</button>
<input type="text" name="username" id="username"><br>

<button id="btn1">按钮</button>
用户名称：<input type="text" name="username" id="username1"><br>
年龄：<input type="text" name="age" id="age"><br>

</body>

</html>
